package com.splic.product.service.impl;

import java.util.Date;
import java.util.List;
import com.splic.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.splic.product.mapper.UserThirdBindMapper;
import com.splic.product.domain.UserThirdBind;
import com.splic.product.service.UserThirdBindService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 用户三方信息绑定Service业务层处理
 * 
 * @author singe
 * @date 2022-03-15
 */
@Service
public class UserThirdBindServiceImpl implements UserThirdBindService
{
    @Autowired
    private UserThirdBindMapper userThirdBindMapper;

    /**
     * 查询用户三方信息绑定
     * 
     * @param id 用户三方信息绑定主键
     * @return 用户三方信息绑定
     */
    @Override
    public UserThirdBind selectUserThirdBindById(Long id)
    {
        return userThirdBindMapper.selectUserThirdBindById(id);
    }

    /**
     * 查询用户三方信息绑定列表
     * 
     * @param userThirdBind 用户三方信息绑定
     * @return 用户三方信息绑定
     */
    @Override
    public List<UserThirdBind> selectPageList(UserThirdBind userThirdBind)
    {
        return userThirdBindMapper.selectUserThirdBindList(userThirdBind);
    }

    @Override
    public List<UserThirdBind> selectPageLogoutList(UserThirdBind userThirdBind) {
        return userThirdBindMapper.selectUserThirdBindLogoutList(userThirdBind);
    }

    @Override
    public UserThirdBind getByTypeAndUserId(Long userId, String type) {
        return userThirdBindMapper.getByTypeAndUserId(type,userId);
    }

    /**
     * 查询用户三方信息绑定列表
     *
     * @param userThirdBind 用户三方信息绑定
     * @return 用户三方信息绑定
     */
    @Override
    public List<UserThirdBind> selectUserThirdBindList(UserThirdBind userThirdBind)
    {
        return userThirdBindMapper.selectUserThirdBindList(userThirdBind);
    }

    /**
     * 新增用户三方信息绑定
     * 
     * @param userThirdBind 用户三方信息绑定
     * @return 结果
     */
    @Override
    public int insert(UserThirdBind userThirdBind)
    {
        userThirdBind.setCreateTime(DateUtils.getNowDate());
        return userThirdBindMapper.insert(userThirdBind);
    }

    /**
     * 修改用户三方信息绑定
     * 
     * @param userThirdBind 用户三方信息绑定
     * @return 结果
     */
    @Override
    public int update(UserThirdBind userThirdBind)
    {
        userThirdBind.setUpdateTime(DateUtils.getNowDate());
        return userThirdBindMapper.update(userThirdBind);
    }


    /**
     * 删除用户三方信息绑定信息
     * 
     * @param id 用户三方信息绑定主键
     * @return 结果
     */
    @Override
    public int deleteById(Long id)
    {
        UserThirdBind userThirdBind = userThirdBindMapper.selectUserThirdBindById(id);
        userThirdBindMapper.deleteLogoutThirdBindById(id);

        userThirdBindMapper.insertLogOutBackUp(userThirdBind);
        return 1;
    }

    @Override
    public int deleteLogoutById(Long id) {
        return userThirdBindMapper.deleteLogoutThirdBindById(id);
    }

    /**
     * 修改用户三方信息绑定
     *
     * @param userThirdBind 用户三方信息绑定信息
     * @return 结果
     */
    @Override
    @Transactional
    public int saveOrUpdate(UserThirdBind userThirdBind)
    {
        if(userThirdBind.getId() != null){
            userThirdBind.setUpdateTime(new Date());
            return userThirdBindMapper.update(userThirdBind);
        }else{
            userThirdBind.setCreateTime(new Date());
            return userThirdBindMapper.insert(userThirdBind);
        }
    }

    @Override
    public UserThirdBind getByTypeAndValue(String type, String value) {
        return userThirdBindMapper.getByTypeAndValue(type,value);
    }
}
